package com.nike.controller;

import com.jfinal.plugin.activerecord.Page;
import com.jfinal.upload.UploadFile;
import com.nike.model.Brand;
import com.nike.router.RouterMapping;
import com.nike.utils.AttachmentUtils;
/**
 * 品牌列表
 * 
 * @author wuhantao
 *
 */
@RouterMapping(url = "/brand", viewPath = "/view/brand")
public class BrandController extends BaseController<Brand> {
	/**
	 * 列表
	 */
	public void index() {
		Page<Brand> page = Brand.DAO.doPaginate(1, 10);
		setAttr("page", page);
		render("list.html");
	}
	/**
	 * 插入页面
	 */
	public void toAdd() {
		render("add.html");
	}
	/**
	 * 保存
	 */
	public void insert() {
		// 上传文件、按照日期存放
		UploadFile logo = getFile();
		// 获得form提交的数据
		Brand brand = getModel(Brand.class, "brand");
		// 判断是不是图片
		boolean isImage = AttachmentUtils.isImage(logo.getFileName());
		if (!isImage) {
			// 不是图片
		}
		String filePath = AttachmentUtils.moveFile(logo);
		brand.set("logo", filePath);
		saved(brand);
		redirect("/brand");
	}
	/**
	 * 删除
	 */
	public void delete() {
		String id = getPara("id");
		Brand.DAO.deleteById(id);
		redirect("/brand");
	}

}
